<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>找回密码</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link data-th-href="@{static/jqgrid/css/bootstrap.css}" rel="stylesheet">
<link rel="stylesheet" type="text/css" data-th-href="@{static/jqgrid/css/style.css}" />
<link rel="stylesheet" type="text/css" data-th-href="@{static/jqgrid/css/body.css}" />
<script type="text/javascript" src="static/bootstrapJS/jquery.js"></script>
<script type="text/javascript" src="static/bootstrapJS/bootstrap.js"></script>
</head>
<body>
	<div class="container">
		<div id="logo" >
		<div id="denlu">
			<form action="" id="myform" method="post" class="form-horizontal" >
				<div class="form-group">
					<label for="user" class="col-md-4 control-label" >电子邮箱</label>
					<div class="col-md-6">
						<input type="text" class="form-control" name="username" id = "username" onchange="fun(this.value);" placeholder="租户管理员登录邮箱">
					</div>
				</div>
				<div class="col-md-offset-5" style="margin-top: -10px;"><label id="username_ereer"></label></div>
				<div class="form-group">
					<label for="pass" class="col-md-4 control-label">验证码</label>
					<div class="col-md-4">
						<input type="text" onchange="fun_1(this.value);" class="form-control" name="code" id = "code" placeholder="验证码">
					</div>
					<div class="col-md-3">
						<label class="control-label" style="padding-top: 0px;"><input disabled="disabled" type = "button" id="yzm" class="btn btn-success" value="发送验证码" /></label>
					</div>
				</div>
				<div class="col-md-offset-5" style="margin-top: -10px;"><label id="code_ereer"></label></div>
				<div id="zhmm_1" style="display: none">
					<div class="form-group">
						<label for="pass" class="col-md-4 control-label">请输入新密码</label>
						<div class="col-md-6">
							<input type="password" class="form-control" name="pwd1" id = "pwd1" placeholder="请输入新密码">
						</div>
					</div>
					<div class="col-md-offset-5" style="margin-top: -10px;"><label id="pwd1_ereer"></label></div>
					<div class="form-group">
						<label for="pass" class="col-md-4 control-label">请确认新密码</label>
						<div class="col-md-6">
							<input type="password" class="form-control" name="pwd2" id = "pwd2" placeholder="请确认新密码">
						</div>
					</div>
					<div class="col-md-offset-5" style="margin-top: -10px;"><label id="pwd2_ereer"></label></div>
					<div class="form-group" style="margin-left: 480px;">
						<div class="col-md-7 col-md-offset-5">
							<button type="button" id = "btn_1" class="btn btn-success">确定</button>
						</div>
					</div>
				</div><br>
			</form>
		</div>
	</div>
	</div>
	<script type="text/javascript">
		var a = window.innerHeight - 100 + "px";
		$("#logo").css('height', a);	
		function CheckMail(mail) {
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(mail)) 
				return true;
			else {
				return false;
			}
		}
		function fun(str){
			if(CheckMail(str)){
				$.post('username', {username: str}, function(data){				
					if(!data){
						$("#username_ereer").html("您输入的邮箱格式有误！");
					}else{
						$("#yzm").prop('disabled', false);
					}
				});
			}else{
				$("#username_ereer").html("您输入的邮箱格式有误！");
			}
		}

		var code = -1;
		var dsq1;
		$("#yzm").click(function(){
			code = -1;
			var username = $("#username").val();
			$.post('username', {username: username}, function(data){
				if(data){
					$.post('yx', {username: username}, function(data1){
						code = data1;
						dsq1 = setInterval("sj();", 1000);
					});
				}
			});				
		});
		function fun_1(str){
			if(code == str){
				$("#zhmm_1").css("display", "block");
			}else{
				$("#code_ereer").html("验证码输入错误！");
			}
		}
		var i = 60;
		function sj(){
			$("#yzm").val("("+i+")获取验证码");
			$("#yzm").prop('disabled', true);
			i--;
			if(i == 0){
				i = 60;
				window.clearInterval(dsq1);
				code = -1;
				$("#yzm").val("重新获取验证码");
				$("#yzm").prop('disabled', false);
			}
		}
		$("#btn_1").click(function(){
			var username = $("#username").val();
			var pwd1 = $("#pwd1").val();
			var pwd2 = $("#pwd2").val();
			var code1 = $("#code").val();
			
			if(pwd1 == "" || pwd1 == null){
				$("#pwd1_ereer").html("请输入新密码！");
			}else if(pwd2 == "" || pwd2 == null){
				$("#pwd2_ereer").html("请再次输入新密码！");
			}else if(pwd1 != pwd2){
				$("#pwd2_ereer").html("两次密码输入不一致！");
			}else{
				$.post('username', {username: username}, function(data){
					if(data){
						$.post("zhmm1", {"username": username, "password": pwd1}, function(data){
							alert(data);
							window.location.href="login";
						});
					}
				});	
			}
		});
	</script>
</body>
</html>